<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>收银台</title>
    <link rel="stylesheet" href="/static/cash//css/index.css">
    <script src="/static/cash/js/jquery-3.2.1.min.js"></script>
    <link rel="stylesheet" href="__STATIC__/plugs/layui/css/layui.css?ver={:date('ymd')}" />
    <script src="__STATIC__/plugs/layui/layui.all.js" charset="utf-8"></script>
    <style media="print">
        @page {
            size: auto;
            margin: 0mm;
        }
    </style>
</head>

<body>
    <header>
        <div>
            <img src="/static/cash/img/logo.png" alt="">
            <div>收银台</div>
        </div>
        <div>
            <a href="javascript:;" onclick="jiaoban()">交班</a>
            <a href="javascript:;" onclick="rijie()">日结 </a>
            <a href="javascript:;" onclick="logout()">
                <img src="/static/cash/img/esc.png" alt="">
            </a>
        </div>
    </header>
    <div class="content">
        <div>
            <!-- 会员 -->
            <div>
                <div>会员</div>
                <div>
                    <input type="text" name="mobile" placeholder="会员手机号/会员卡" value="">
                    <div class="member-click">查询</div>
                </div>
                <div id="member_money">0.00</div>
            </div>
            <!--扫一扫 -->
            <div>
                <div>扫码</div>
                <input type="text" name="qrcode" placeholder="扫描支付码    微信/支付宝">
                <div class="coupon-click">优惠券</div>
            </div>
            <!-- 选择之后的标题 -->
            <div>
                <div>操作</div>
                <div>商品</div>
                <div>规格</div>
                <div>价格</div>
                <div>数量</div>
                <div>折扣</div>
            </div>
            <!-- 购买商品 -->
            <div id="list">
                <!-- 需要插入的地方 -->

                <!-- 需要插入的地方 -->
            </div>
            <!--购买商品-->

            <div>
                <a href="javascript:;" onclick="qingkong();">清空</a>
                <div class="calculator-click">折扣</div>
                <div onclick="choose_all_goods()">全选</div>
            </div>
        </div>
        <div>
            <!-- 商品标题 -->
            <div>
                {foreach name="goods_category" item="v"}
                    <div class="right {if condition='$cat_id eq $v.id'}right-zhong{/if}" onclick="select_catrgory({$v.id})">
                        <p>
                            <img src="{$v.logo}" alt="">
                        </p>
                        <p>{$v.title}</p>
                    </div>
                {/foreach}
            </div>

            <!-- 商品列表内容 -->
            <div id="goods_list">

            </div>
            <!-- 商品列表内容 -->

            <!-- 分页 -->
            <div id="fpage" style="text-align:right;">

            </div>
            <!-- 数量选择 -->
            <div>
                <div onclick="set_num(1)">
                    1
                </div>
                <div onclick="set_num(2)">
                    2
                </div>
                <div onclick="set_num(3)">
                    3
                </div>
                <div onclick="set_num(4)">
                    4
                </div>
                <div onclick="add_num(1)">
                    +1
                </div>
                <div onclick="add_num(2)">
                    +2
                </div>
                <div onclick="add_num(3)">
                    +3
                </div>
                <div onclick="dec_num(1)">
                    -1
                </div>
                <div onclick="dec_num(2)">
                    -2
                </div>
                <div onclick="dec_num(3)">
                    -3
                </div>
            </div>
        </div>
    </div>
    <footer>
        <div>
            <div class="pay-popup">

            </div>
            <div class="pay-popup">

            </div>
            <div class="pay-popup">

            </div>
            <div class="pay-popup">

            </div>
            <div class="pay-popup">

            </div>
            <div class="pay-popup">

            </div>
            <a href="javascript:;" onclick="yuding()">
                预订单结账
            </a>
        </div>
        <div>
            <div>
                <div>
                    收款
                </div>
                <div>

                    <label for="yue">
                        <span>余额</span>
                        <input type="text" placeholder="0" name="yue" id="yue" onkeyup="value=value.replace(/[^\d]\./g,'')">
                    </label>
                </div>
                <div class="pay" data-id="2">
                    微信
                </div>
                <div class="pay" data-id="1">
                    支付宝
                </div>
                <div class="pay" data-id="4">
                    现金
                </div>
                <div class="pay" data-id="5">
                    银行卡
                </div>
                <div class="pay" data-id="6">
                    美团
                </div>
                <div class="pay" data-id="7">
                    饿了么
                </div>
            </div>
            <div>
                <a href="{:url('Guadan/get_order_list')}">结算挂单</a>
                <div onclick="guadan()">
                    挂单
                </div>
            </div>
        </div>
        <div>
            <div class="total">
                <span>总计</span>
                <span id="total_amount">0.00</span>
            </div>
            <div class="total">
                <span>实收</span>
                <span id="final_amount">0.00</span>
            </div>
            <label for="cash" class="xianjin hei">
                <span>现金</span>
                <input type="text" placeholder="0" value="0" name="cash" id="cash" onkeyup="count_zhaoling()">
            </label>
            <!--<div class="total hei">-->
            <!--<span>现金</span>-->
            <!--&lt;!&ndash;<span id="cash">0.00</span>&ndash;&gt;-->
            <!--<input type="text" placeholder="0" value="0" name="cash" id="cash" onkeyup="count_zhaoling()">-->
            <!--</div>-->
            <div class="total hei">
                <span>找零</span>
                <span id="zhaoling">0.00</span>
            </div>
            <div class="huiyuan memberPay-click">会员充值</div>
            <a href="{:url('Order/index')}">订单查询/退款/自取</a>
            <a href="javascript:;" onclick="jiezhang()">结账</a>
        </div>
    </footer>
    <!-- 优惠卷弹出层 -->
    <div class="coupon"></div>
    <div class="coupon-content">
        <div>可用优惠
        </div>
        <div id="coupon">
            <!-- 优惠券循环开始 -->

            <!-- 优惠券循环结束 -->
        </div>
        <div class="coupon-esc ">
            取消
        </div>
        <p>每个订单只能使用一张优惠券</p>
    </div>
    <!--优惠券 end-->


    <div class="member">

    </div>

    <div class="member-content">
        <div>
            会员信息
        </div>
        <div>
            <div>
                <img id="vip_logo" src="/static/cash/img/tiandian.png" alt="">
            </div>
            <div>
                <div>
                    <div id="vip_realname">王女士</div>
                    <div id="vip_level">铂金会员</div>
                    <div id="vip_coupon">拥有 4 张优惠券</div>
                </div>
                <p id="vip_pay_code">会员卡：370910023</p>
                <p id="vip_mobile">手机号：15666822300</p>
            </div>
        </div>
        <div>
            <p id="vip_money">余额：328.5</p>
            <p id="vip_points">积分：2218</p>
        </div>
        <div class="member-esc">确定</div>
    </div>


    <div class="calculator">

    </div>
    <div class="calculator-content">
        <div>
            输入折扣
        </div>
        <div class="show"></div>
        <div class="jisuanqi">
            <div class="key">1</div>
            <div class="key">2</div>
            <div class="key">3</div>
        </div>
        <div class="jisuanqi">
            <div class="key">4</div>
            <div class="key">5</div>
            <div class="key">6</div>
        </div>
        <div class="jisuanqi">
            <div class="key">7</div>
            <div class="key">8</div>
            <div class="key">9</div>
        </div>
        <div class="jisuanqi">
            <div class="key">0</div>
            <div class="key">.</div>
            <div class="kong" style="background-color: #5ba8ff;font-size: 12px;color: #ffffff;">清空</div>
        </div>
        <div class="" onclick="count_discount()">确认</div>
        <div class="calculator-esc">取消</div>
    </div>
    <div class="memberPay">

    </div>
    <div class="memberPay-content">
        <div>
            会员充值
        </div>
        <div>
            <div>会员</div>
            <input type="text" name="user_mobile" placeholder="输入会员手机号">
            <div onclick="get_member();" >搜索</div>
        </div>
        <div>
            <div>金额</div>
            <input type="text" name="recharge_money" placeholder="填写金额">
        </div>
        <div>
            <div>收款</div>
            <div class="again" data-id="1">支付宝</div>
            <div class="again again-zhong" data-id="2">微信</div>
            <div class="again" data-id="4">现金</div>
            <div class="again" data-id="5">银行卡</div>
        </div>
        <div>
            <div>扫码</div>
            <input type="text" name="recharge_code" placeholder="扫描支付码    微信/支付宝">
        </div>
        <div onclick="recharge()">充值</div>
        <div class="memberPay-esc">取消</div>
    </div>

    <!--选择商品规格 start-->
    <div class="size">

    </div>
    <div class="size-content">
        <div id="size-roll">
            <!-- 循环开始 -->

            <!-- 循环结束 -->
        </div>
        <div class="" onclick="pre_count_price();">确认</div>
        <div class="size-esc">取消</div>
        <div stype="display:none;" id="goods_id"></div>
    </div>

    <!--使用的优惠券 ID-->
    <input type="hidden" name="use_coupon_id" value="">
    <div style="display:none;" id="use_coupon_amount">0</div>
    <div style="display:none;" id="user_id">0</div>

    <!--选择商品规格 end-->


    <!--打印区域 start-->
    <div style="display: none">
        <div id="print-area">
            <table id="print">
            </table>
        </div>
    </div>
    <!--打印区域 end-->
    <script>
        $(function () {
            // 左侧商品单选
            $('.xuanze').click(function () {
                $('.xuanze').removeClass('zhong');
                $(this).addClass('zhong');
            });

            // 右侧商品单选
            $('.right').click(function () {
                $('.right').removeClass('right-zhong');
                $(this).addClass('right-zhong');
            });

            // 底部付款方式单选
            $('.pay').click(function () {
                var user_money = parseFloat($('#yue').val()).toFixed(2);            //会员余额
                if(isNaN(user_money)){
                    user_money = parseFloat(0).toFixed(2);
                }

                var final_amount = parseFloat($('#final_amount').text()).toFixed(2);    //最终支付价
                var use_money = parseFloat(parseFloat(final_amount)-parseFloat(user_money)).toFixed(2);

                if(use_money <= 0){
                    use_money = 0;
                }

                $('.pay').removeClass('pay-zhong');
                if(use_money != 0){
                    $(this).addClass('pay-zhong');
                    let number = $(this).index() - 2;
                    $('.pay-popup').css('visibility', 'hidden');
                    $('.pay-popup').eq(number).text(use_money);
                    $('.pay-popup').eq(number).css('visibility', 'visible');
                }else{
                    layer.msg('余额充足，不能使用其它付款方式', {
                        icon: 2,
                        time: 1000
                    });
                    return false; //重要
                }
            });

            // 优惠卷弹出层
            $('.coupon-click').click(function () {
                var mobile = $('input[name=mobile]').val();
                var final_amount = parseFloat($('#final_amount').text()).toFixed(2);
                var user_id = parseInt($('#user_id').text());
                if(user_id == ''){
                    layer.msg('请先查询会员信息', {
                        icon: 2,
                        time: 1000
                    });
                    return false; //重要
                }

                if(mobile == ''){
                    layer.msg('未输入会员手机号或会员卡号，不能查询优惠券', {
                        icon: 2,
                        time: 1000
                    });
                    return false; //重要
                }

                if(final_amount == ''){
                    layer.msg('请先选择商品', {
                        icon: 2,
                        time: 1000
                    });
                    return false; //重要
                }
                var goods_id = [];
                var goods_spec_id = [];
                var goods_num = [];
                $(".xuanze").each(function () {
                    goods_id.push($(this).parent().find("input[name='goods_id[]']").val());
                    goods_spec_id.push($(this).parent().find("input[name='goods_spec_id[]']").val());
                    goods_num.push($(this).parent().find("input[name='goods_num[]']").val());
                })

                if(goods_id == ''){
                    layer.msg('请先选择商品', {
                        icon: 2,
                        time: 1000
                    });
                    return false; //重要
                }

//                $("input[name='goods_spec_id[]']").each(function () {
//                    goods_spec_id.push($(this).val());
//                })
//
//                $("input[name='goods_num[]']").each(function () {
//                    goods_num.push($(this).val());
//                })

                $.post("{:url('Countprice/get_coupon')}",
                    {mobile:mobile,goods_id:goods_id,goods_spec_id:goods_spec_id,goods_num:goods_num},
                    function(data){
                        if(data.code == 1){         //查询成功
                            var html = '';
                            for(var i=0;i<data.data.length;i++){
                                html += '<div><div><span>￥</span><span>'+data.data[i]["reduce"]+'</span></div><div><p>满'+data.data[i]["morethan"]+'减'+data.data[i]["reduce"]+'（'+data.data[i]["title"]+'）</p><p>'+data.data[i]["start_time"]+'-'+data.data[i]["end_time"]+'</p></div><div onclick="use_coupon('+data.data[i]["reduce"]+','+data.data[i]["coupon_id"]+')">使用</div></div>';
                            }
                            $('#coupon').empty();
                            $('#coupon').html(html);

                            $('.coupon').css('display', 'block');
                            $('.coupon-content').css('display', 'block');
                        }else{
                            layer.msg(data.msg, {
                                icon: 2,
                                time: 1000
                            });
                            return false; //重要
                        }
                    }
                );
            });
            $('.coupon-esc').click(function () {
                $('.coupon').css('display', 'none');
                $('.coupon-content').css('display', 'none');
            });
            $('.coupon').click(function () {
                $('.coupon').css('display', 'none');
                $('.coupon-content').css('display', 'none');

            });


            // 会员信息弹出层 -- 查询会员信息
            $('.member-click').click(function () {
                var user_id = parseInt($('#user_id').text());
                var mobile = $('input[name=mobile]').val();
                var total_amount = parseFloat($('#total_amount').text()).toFixed(2);
                var final_amount = parseFloat($('#final_amount').text()).toFixed(2);        //最终你支付金额
                var cash = parseFloat($('#cash').val()).toFixed(2);        //现金
                if(mobile == ''){
                    layer.msg('请输入会员手机号或会员卡号', {
                        icon: 2,
                        time: 1000
                    });
                    return false;
                }
                $.post("{:url('Index/get_member')}",
                    {mobile:mobile},
                    function(data){
                        if(data.code == 1){
                            $('#member_money').text(data.data.user_money);
                            $('#yue').val(data.data.user_money);
                            //放入会员信息
                            $('#vip_logo').attr('src',data.data.logo);
                            $('#vip_realname').text(data.data.realname);
                            $('#vip_level').text(data.data.level_title);
                            $('#vip_coupon').text('拥有'+data.data.coupon_count+'张优惠券');
                            $('#vip_pay_code').text('会员卡：'+data.data.pay_code);
                            $('#vip_mobile').text('手机号：'+data.data.mobile);
                            $('#vip_money').text('余额：'+data.data.user_money);
                            $('#vip_points').text('积分：'+data.data.pay_points);

                            $('.member').css('display', 'block');
                            $('.member-content').css('display', 'block');


                            if(user_id != data.data.uid){       //会员重置
                                $('#list').empty();              //清空商品
                                $('#coupon').empty();
                                $('#total_amount').text('0.00');
                                $('#final_amount').text('0.00');
                                $('#zhaoling').text('0.00');
                                $('input[name=use_coupon_id]').val('');
                                $('#use_coupon_amount').text(0);
                            }else{
//                                $('input[name=use_coupon_id]').val('');
//                                $('#use_coupon_amount').text(0);
                                var zhaoling = parseFloat(parseFloat(cash)-parseFloat(total_amount)).toFixed(2);
                                $('#zhaoling').text(zhaoling);
//                                $('#final_amount').text(total_amount);
                            }
                            $('#user_id').text(data.data.uid);
                        }else{
                            layer.msg('找不会员信息，请重新查询', {
                                icon: 2,
                                time: 1000
                            });
                            $('#list').empty();              //清空商品
                            $('#coupon').empty();
                            $('#total_amount').text('0.00');
                            $('#final_amount').text('0.00');
                            $('#zhaoling').text('0.00');
                            $('input[name=use_coupon_id]').val('');
                            $('#use_coupon_amount').text(0);
                            $('#user_id').text('');

                            return false;
                        }
                    }
                );
            });


            $('.member-esc').click(function () {
                $('.member').css('display', 'none');
                $('.member-content').css('display', 'none');

            });
            $('.member').click(function () {
                $('.member').css('display', 'none');
                $('.member-content').css('display', 'none');
            });

            //会员信息弹出关闭


            // 会员充值弹出层
            $('.memberPay-click').click(function () {
                $('.memberPay').css('display', 'block');
                $('.memberPay-content').css('display', 'block');
            });
            $('.memberPay-esc').click(function () {
                $('.memberPay').css('display', 'none');
                $('.memberPay-content').css('display', 'none');

            });
            $('.memberPay').click(function () {
                $('.memberPay').css('display', 'none');
                $('.memberPay-content').css('display', 'none');
            });
            // 充值弹出框里面的单选边
            $('.again').click(function () {
                $('.again').removeClass('again-zhong');
                $(this).addClass('again-zhong');
            });

            // 计算器 -- 打开
            $('.calculator-click').click(function () {

                let show = $('.show');
                show.html('');

                var num = 0;
                var sign = 1;
                $('.xuanze').each(function () {
                    if($(this).hasClass('zhong')){         //有属性
                        if($(this).attr('data-is-diannei') == 1){
                            num++;
                        }else{
                            sign = 0;
                        }
                    }
                })

                if(sign == 0){
                    layer.msg('选中的商品中存在不支持打折的商品，仅店内自营商品支持打折，请重新选择', {
                        icon: 2,
                        time: 1500
                    });
                    return false; //重要
                }

                if(num == 0){
                    layer.msg('请选择打折商品', {
                        icon: 2,
                        time: 1000
                    });
                    return false; //重要
                }

                $('.calculator').css('display', 'block');
                $('.calculator-content').css('display', 'block');
            });

            //计算器 -- 关闭
            $('.calculator-esc').click(function () {
                $('.calculator').css('display', 'none');
                $('.calculator-content').css('display', 'none');

            });
            //
            $('.calculator').click(function () {
                $('.calculator').css('display', 'none');
                $('.calculator-content').css('display', 'none');
            });
            $('.key').click(function () {
                let show = $('.show');
                show.html(show.html() + $(this).html())
            });
            $('.kong').click(function () {
                let show = $('.show');
                show.html('');
            });

            //选择商品属性 -- start
            //关闭商品属性弹出框
            $('.size-esc').click(function () {
                $('.size').css('display', 'none');
                $('.size-content').css('display', 'none');

            });
            $('.size').click(function () {
                $('.size').css('display', 'none');
                $('.size-content').css('display', 'none');
            });
            //选择商品属性 -- end
        });

    </script>

    <script>
        /**
         * 加载完成查询商品信息
         */
        $(function(){
            var cat_id = "{$cat_id}";
            $.post("{:url('Index/get_goods')}", //ajax查询商品信息
                {cat_id: cat_id},
                function (data) {
                    if (data.code == 1){
                        var data = data.data;
                        layui.use(['laypage', 'layer'],function(){
                            var laypage = layui.laypage,
                                layer = layui.layer;
                            //调用分页
                            laypage.render({
                                elem: 'fpage',
                                count: data.length,
                                limit: 15,
                                groups: 1,
                                jump: function (obj) {
                                    //模拟渲染
                                    document.getElementById('goods_list').innerHTML =
                                        function () {
                                            var arr = [],
                                                thisData = data.concat().splice(obj.curr * obj.limit -obj.limit, obj.limit);
                                            layui.each(thisData, function (index, item) {
                                                var html = '<div class="size-click" data-id="'+item.id+'" data-dn="'+item.is_diannei+'" onclick="size_click('+item.id+');"><p>'+item.goods_name+'</p><p>'+item.price+'</p></div>';
                                                arr.push(html);
                                            });
                                            return arr.join('');
                                        }();
                                }
                            });
                        });
                    } else {
                        layer.msg('找不到商品信息', {
                            icon: 2,
                            time: 1000
                        });
                        return false; //重要
                    }
                }
            );
        });

        /**
         * ajax查询商品
         */
        function select_catrgory(cat_id){
            $.post("{:url('Index/get_goods')}", //ajax查询商品信息
                {cat_id: cat_id},
                function (data) {
                    if (data.code == 1){
                        var data = data.data;
                        layui.use(['laypage', 'layer'],function(){
                            var laypage = layui.laypage,
                                layer = layui.layer;
                            //调用分页
                            laypage.render({
                                elem: 'fpage',
                                count: data.length,
                                limit: 15,
                                groups: 1,
                                jump: function (obj) {
                                    //模拟渲染
                                    document.getElementById('goods_list').innerHTML =
                                        function () {
                                            var arr = [],
                                                thisData = data.concat().splice(obj.curr * obj.limit -obj.limit, obj.limit);
                                            layui.each(thisData, function (index, item) {
                                                var html = '<div class="size-click" data-id="'+item.id+'" data-dn="'+item.is_diannei+'" onclick="size_click('+item.id+');"><p>'+item.goods_name+'</p><p>'+item.price+'</p></div>';
                                                arr.push(html);
                                            });
                                            return arr.join('');
                                        }();
                                }
                            });
                        });
                    } else {
                        layer.msg('找不到商品信息，请选择其它分类', {
                            icon: 2,
                            time: 1000
                        });
                        return false; //重要
                    }
                }
            );
        }

        /**
         * 查询商品属性
         */
        function size_click(id){
            $.post("{:url('Index/get_goods_specs')}",
                {id:id},
                function(data){
                    $('#size-roll').empty();         //清空元素
                    $('#goods_id').empty();         //清空元素
                    if(data.code == 1){
                        if(data.data.is_shuxing == 1){
                            var html = '';
                            for(var i=0;i<data.data.spec_title.length;i++){
                                html += '<div class="size-headline">'+data.data.spec_title[i]+'</div><div class="size-body">';
                                for(var k=0;k<data.data.spec_detail[i].length;k++){
                                    if(k == 0){
                                        html += '<div class="specs size-zhogn" data-id="'+data.data.spec_detail[i][k].id+'" onclick="select_spec(this,'+data.data.spec_detail[i][k].id+')"><p>'+data.data.spec_detail[i][k].detail+'</p></div>';
                                    }else{
                                        html += '<div class="specs" data-id="'+data.data.spec_detail[i][k].id+'" onclick="select_spec(this,'+data.data.spec_detail[i][k].id+')"><p>'+data.data.spec_detail[i][k].detail+'</p></div>';
                                    }
//                                console.log(data.data.spec_detail[i][k]);
                                }
                                html +='</div>';
                            }

                            $('#size-roll').html(html);         //放入元素
                            $('#goods_id').text(data.data.goods_id);         //放入商品id

                            // 商品规格弹出层
                            $('.size').css('display', 'block');
                            $('.size-content').css('display', 'block');
                        }else{
                            var goods_id =data.data.goods_id;           //商品id
                            var spec_details = '0,';
                            var mobile = $('input[name=mobile]').val();
                            var total_amount = parseFloat($('#total_amount').text()).toFixed(2);          //总计
                            var final_amount = parseFloat($('#final_amount').text()).toFixed(2);          //实收
                            var cash = parseFloat($('#cash').val()).toFixed(2);          //现金
                            var zhaoling = parseFloat($('#zhaoling').text()).toFixed(2);          //找零

                            $.post("{:url('Countprice/index')}",
                                {goods_id:goods_id,spec_details:spec_details,mobile:mobile},
                                function(data){
                                    if(data.code == 1){
                                        $('.xuanze').removeClass('zhong');           //移除元素的选中
//                        console.log($('#sp_'+data.data.goods_spec_id).length);
                                        if($('#sp_'+data.data.goods_spec_id).length == 0){          //不存在商品
                                            var html = '<div id="sp_'+data.data.goods_spec_id+'" data-id-diannei="'+data.data.is_diannei+'"><div onclick="del_goods(this)"><img src="/static/cash/img/X.png" alt=""></div>';

                                            if(data.data.is_diannei == 1){          //店内商品可以全选
                                                html += '<div class="xuanze zhong" data-is-diannei="'+data.data.is_diannei+'" onclick="choose_goods(this)"><div>';
                                            }else{
                                                html += '<div class="xuanze zhong" data-is-diannei="'+data.data.is_diannei+'" onclick="choose_goods(this)"><div>';
                                            }

                                            html += '<div>'+data.data.name+'</div></div><div>'+data.data.title+'</div><div class="s_goods_amount">'+data.data.final_amount+'</div><div class="s_goods_num">1</div><div class="s_goods_discount">0</div>';

                                            if(data.data.is_diannei == 1){
                                                html += '<div></div>';
                                            }else{
                                                html += '<div></div>';
                                            }

                                            html += '</div><input type="hidden" name="goods_id[]" value="'+data.data.goods_id+'"><input type="hidden" name="goods_spec_id[]" value="'+data.data.goods_spec_id+'"><input type="hidden" name="goods_num[]" value="1"><input type="hidden" name="goods_final_amount[]" value="'+data.data.final_amount+'"><input type="hidden" name="goods_discount[]" value="0"></div>';

                                            $('#list').append(html);

                                            var goods_price = parseFloat(data.data.final_amount).toFixed(2);            //选中商品的价格

                                            total_amount = parseFloat(parseFloat(total_amount)+parseFloat(goods_price)).toFixed(2);
                                            final_amount = parseFloat(parseFloat(final_amount)+parseFloat(goods_price)).toFixed(2);
                                            zhaoling = parseFloat(parseFloat(cash)-parseFloat(final_amount)).toFixed(2);
                                            $('#total_amount').text(total_amount);
                                            $('#final_amount').text(final_amount);
                                            $('#zhaoling').text(zhaoling);

                                        }else{          //存在商品更新商品数据
                                            $('.xuanze').removeClass('zhong');
                                            var goods_price = parseFloat(data.data.final_amount).toFixed(2);            //选中商品的价格
                                            var goods_num = parseInt($('#sp_'+data.data.goods_spec_id).find('.s_goods_num').text());
                                            var goods_final_amount = parseFloat($('#sp_'+data.data.goods_spec_id).find('input[name="goods_final_amount[]"]').val()).toFixed(2);         //商品单价
                                            var discount = parseFloat($('#sp_'+data.data.goods_spec_id).find('.s_goods_discount').text()).toFixed(1);

                                            if(discount > 1){
                                                var pre_amount = parseFloat(parseInt(goods_num)*parseFloat(goods_final_amount)*parseFloat(discount)/10).toFixed(2);       //之前的商品总价
                                            }else{

                                                var pre_amount = parseFloat(parseInt(goods_num)*parseFloat(goods_final_amount)).toFixed(2);
                                            }

                                            goods_num = parseInt(parseInt(goods_num)+parseInt(1));          //商品数量
                                            if(discount > 1){
                                                var cur_amount = parseFloat(parseInt(goods_num)*parseFloat(goods_price)*parseFloat(discount)/10).toFixed(2);      //当前商品总价
                                            }else{
                                                var cur_amount = parseFloat(parseInt(goods_num)*parseFloat(goods_price)).toFixed(2);      //当前商品总价
                                            }

                                            $('#sp_'+data.data.goods_apec_id).find('.s_goods_amount').text(goods_price);
                                            $('#sp_'+data.data.goods_spec_id).find("input[name='goods_final_amount[]']").val(goods_price);
                                            $('#sp_'+data.data.goods_spec_id).find('.s_goods_num').text(goods_num);
                                            $('#sp_'+data.data.goods_spec_id).find("input[name='goods_num[]']").val(goods_num);
//
                                            total_amount = parseFloat(parseFloat(total_amount)-parseFloat(pre_amount)+parseFloat(cur_amount)).toFixed(2);
                                            final_amount = parseFloat(parseFloat(final_amount)-parseFloat(pre_amount)+parseFloat(cur_amount)).toFixed(2);
                                            zhaoling = parseFloat(parseFloat(cash)-parseFloat(final_amount)).toFixed(2);

                                            $('#total_amount').text(total_amount);
                                            $('#final_amount').text(final_amount);
                                            $('#zhaoling').text(zhaoling);
                                            console.log(data.data.goods_spec_id);
                                            $('#sp_'+data.data.goods_spec_id).find('.xuanze').addClass('zhong');
                                        }

                                        //重置付款方式
                                        $('.pay').removeClass('pay-zhong');
                                        $('.pay-popup').css('visibility','hidden');

                                        //关闭弹出层
                                        $('.size').css('display', 'none');
                                        $('.size-content').css('display', 'none');
                                    }else{
                                        layer.msg(data.msg, {
                                            icon: 2,
                                            time: 1000
                                        });
                                        return false; //重要
                                    }
                                }
                            );
                        }
                    }else{
                        layer.msg('找不到商品信息，请重试', {
                            icon: 2,
                            time: 1000
                        });
                        return false; //重要
                    }
                }
            );
        }

        /**
         * 选择商品属性
         */
        function select_spec(obj,id){
            $(obj).parent().find('div').removeClass('size-zhogn');      //清空元素样式
            $(obj).addClass('size-zhogn');
        }

        /**
         * 预计算商品价格
         */
        function pre_count_price(){
            var mobile = $('input[name=mobile]').val();
            var goods_id = $('#goods_id').text();
            var spec_details = '';
            var total_amount = parseFloat($('#total_amount').text()).toFixed(2);          //总计
            var final_amount = parseFloat($('#final_amount').text()).toFixed(2);          //实收
            var cash = parseFloat($('#cash').val()).toFixed(2);          //现金
            var zhaoling = parseFloat($('#zhaoling').text()).toFixed(2);          //找零
            $('.specs').each(function () {
                if($(this).hasClass('size-zhogn')){         //有属性
//                    console.log($(this).attr('data-id'));
                    spec_details += $(this).attr('data-id')+',';
                }
            })

            if(spec_details == ''){
                layer.msg('请选择商品属性', {
                    icon: 2,
                    time: 1000
                });
                return false; //重要
            }
            $.post("{:url('Countprice/index')}",
                {goods_id:goods_id,spec_details:spec_details,mobile:mobile},
                function(data){
                    if(data.code == 1){
                        $('.xuanze').removeClass('zhong');           //移除元素的选中
//                        console.log($('#sp_'+data.data.goods_spec_id).length);
                        if($('#sp_'+data.data.goods_spec_id).length == 0){          //不存在商品
                            var html = '<div id="sp_'+data.data.goods_spec_id+'" data-id-diannei="'+data.data.is_diannei+'"><div onclick="del_goods(this)"><img src="/static/cash/img/X.png" alt=""></div>';

                            if(data.data.is_diannei == 1){          //店内商品可以全选
                                html += '<div class="xuanze zhong" data-is-diannei="'+data.data.is_diannei+'" onclick="choose_goods(this)"><div>';
                            }else{
                                html += '<div class="xuanze zhong" data-is-diannei="'+data.data.is_diannei+'" onclick="choose_goods(this)"><div>';
                            }

                            html += '<div>'+data.data.name+'</div></div><div>'+data.data.title+'</div><div class="s_goods_amount">'+data.data.final_amount+'</div><div class="s_goods_num">1</div><div class="s_goods_discount">0</div>';

                            if(data.data.is_diannei == 1){
                                html += '<div></div>';
                            }else{
                                html += '<div></div>';
                            }

                            html += '</div><input type="hidden" name="goods_id[]" value="'+data.data.goods_id+'"><input type="hidden" name="goods_spec_id[]" value="'+data.data.goods_spec_id+'"><input type="hidden" name="goods_num[]" value="1"><input type="hidden" name="goods_final_amount[]" value="'+data.data.final_amount+'"><input type="hidden" name="goods_discount[]" value="0"></div>';

                            $('#list').append(html);

                            var goods_price = parseFloat(data.data.final_amount).toFixed(2);            //选中商品的价格

                            total_amount = parseFloat(parseFloat(total_amount)+parseFloat(goods_price)).toFixed(2);
                            final_amount = parseFloat(parseFloat(final_amount)+parseFloat(goods_price)).toFixed(2);
                            zhaoling = parseFloat(parseFloat(cash)-parseFloat(final_amount)).toFixed(2);
                            $('#total_amount').text(total_amount);
                            $('#final_amount').text(final_amount);
                            $('#zhaoling').text(zhaoling);

                        }else{          //存在商品更新商品数据
                            $('.xuanze').removeClass('zhong');
                            var goods_price = parseFloat(data.data.final_amount).toFixed(2);            //选中商品的价格
                            var goods_num = parseInt($('#sp_'+data.data.goods_spec_id).find('.s_goods_num').text());
                            var goods_final_amount = parseFloat($('#sp_'+data.data.goods_spec_id).find('input[name="goods_final_amount[]"]').val()).toFixed(2);         //商品单价
                            var discount = parseFloat($('#sp_'+data.data.goods_spec_id).find('.s_goods_discount').text()).toFixed(1);

                            if(discount > 1){
                                var pre_amount = parseFloat(parseInt(goods_num)*parseFloat(goods_final_amount)*parseFloat(discount)/10).toFixed(2);       //之前的商品总价
                            }else{

                                var pre_amount = parseFloat(parseInt(goods_num)*parseFloat(goods_final_amount)).toFixed(2);
                            }

                            goods_num = parseInt(parseInt(goods_num)+parseInt(1));          //商品数量
                            if(discount > 1){
                                var cur_amount = parseFloat(parseInt(goods_num)*parseFloat(goods_price)*parseFloat(discount)/10).toFixed(2);      //当前商品总价
                            }else{
                                var cur_amount = parseFloat(parseInt(goods_num)*parseFloat(goods_price)).toFixed(2);      //当前商品总价
                            }

                            $('#sp_'+data.data.goods_apec_id).find('.s_goods_amount').text(goods_price);
                            $('#sp_'+data.data.goods_spec_id).find("input[name='goods_final_amount[]']").val(goods_price);
                            $('#sp_'+data.data.goods_spec_id).find('.s_goods_num').text(goods_num);
                            $('#sp_'+data.data.goods_spec_id).find("input[name='goods_num[]']").val(goods_num);
//
                            total_amount = parseFloat(parseFloat(total_amount)-parseFloat(pre_amount)+parseFloat(cur_amount)).toFixed(2);
                            final_amount = parseFloat(parseFloat(final_amount)-parseFloat(pre_amount)+parseFloat(cur_amount)).toFixed(2);
                            zhaoling = parseFloat(parseFloat(cash)-parseFloat(final_amount)).toFixed(2);

                            $('#total_amount').text(total_amount);
                            $('#final_amount').text(final_amount);
                            $('#zhaoling').text(zhaoling);
                            console.log(data.data.goods_spec_id);
                            $('#sp_'+data.data.goods_spec_id).find('.xuanze').addClass('zhong');
                        }

                        //重置付款方式
                        $('.pay').removeClass('pay-zhong');
                        $('.pay-popup').css('visibility','hidden');

                        //关闭弹出层
                        $('.size').css('display', 'none');
                        $('.size-content').css('display', 'none');
                    }else{
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 1000
                        });
                        return false; //重要
                    }
                }
            );
        }

        /**
         * 选中商品
         * goods_spec_id   商品属性id
         */
        function choose_goods(obj){
            $('.xuanze').removeClass('zhong');
            $(obj).addClass('zhong');
        }

        /**
         * 选中部商品
         */
        function choose_all_goods(){
            $('.xuanze').removeClass('zhong');
            $('.xuanze').each(function () {
                if($(this).attr('data-is-diannei') == 1){         //有属性
                    $(this).addClass('zhong');
                }
            })
        }
        /**
         * 删除商品
         */
        function del_goods(obj){
            var total_amount = parseFloat($('#total_amount').text()).toFixed(2);
            var final_amount = parseFloat($('#final_amount').text()).toFixed(2);
            var cash = parseFloat($('#cash').val()).toFixed(2);

            var goods_final_amount = parseFloat($(obj).parent().find("input[name='goods_final_amount[]']").val()).toFixed(2);
            var goods_num = parseFloat($(obj).parent().find("input[name='goods_num[]']").val()).toFixed(2);
            var goods_discount = parseFloat($(obj).parent().find("input[name='goods_discount[]']").val()).toFixed(1);
            var goods_amount = parseFloat(0);
            if(goods_discount > 1){         //打折
                goods_amount = parseFloat(parseFloat(goods_final_amount)*parseFloat(goods_num)*parseFloat(goods_discount)/10).toFixed(2);
            }else{
                goods_amount = parseFloat(parseFloat(goods_final_amount)*parseFloat(goods_num)).toFixed(2);
            }
            console.log(goods_amount);
            console.log(total_amount);
            total_amount = parseFloat(parseFloat(total_amount)-parseFloat(goods_amount)).toFixed(2);
            final_amount = parseFloat(parseFloat(final_amount)-parseFloat(goods_amount)).toFixed(2);
            var zhaoling = parseFloat(parseFloat(cash)-parseFloat(total_amount)).toFixed(2);

            $('#total_amount').text(total_amount);
            $('#final_amount').text(total_amount);
            $('#zhaoling').text(zhaoling);

            $(obj).parent().remove();

            $('input[name=use_coupon_id]').val('');         //重置优惠券id
            $('#use_coupon_amount').text('');               //重置优惠券价格

            //重置付款方式
            $('.pay').removeClass('pay-zhong');
            $('.pay-popup').css('visibility','hidden');

//            layer.msg('优惠券已重置，请重新选择', {
//                icon: 0,
//                time: 1500
//            });
//            return false; //重要
        }

        /**
         * 计算折扣
         */
        function count_discount(){
            var reg = /^\d+(\.\d{1,2})?$/;
            var sign = 0;                                           //1表示有选中的店内商品，0表示没选中的店内商品
            var discount = parseFloat($('.show').text());           //当前折扣


            $('.xuanze').each(function () {
                if ($(this).hasClass('zhong') && $(this).attr('data-is-diannei') == 1) {         //选中商品
                    var sign = 1;           //表示有选中的店内商品
                }
            })

            if(isNaN(discount)){
                layer.msg('请输入折扣', {
                    icon: 2,
                    time: 1000
                });
                return false; //重要
            }else if(discount < 1){
                layer.msg('折扣必须大于1', {
                    icon: 2,
                    time: 1000
                });
                return false; //重要
            }else if(!reg.test(discount)){
                layer.msg('折扣最多一位小数', {
                    icon: 2,
                    time: 1000
                });
                return false; //重要
            }

            var discount = parseFloat($('.show').text()).toFixed(1);


            var total_amount = parseFloat($('#total_amount').text()).toFixed(2);
            var final_amount = parseFloat($('#final_amount').text()).toFixed(2);
            var cash = parseFloat($('#cash').val()).toFixed(2);        //现金
            var pre_amount = parseFloat(0).toFixed(2);                  //之前的价格
            var cur_amount = parseFloat(0).toFixed(2);
            $('.xuanze').each(function () {
                if($(this).hasClass('zhong') && $(this).attr('data-is-diannei') == 1){         //选中商品
                    var pre_discount = parseFloat($(this).parent().find("input[name='goods_discount[]']").val()).toFixed(1);        //之前的折扣
                    var goods_spec_id = parseInt($(this).parent().find("input[name='goods_spec_id[]']").val());
                    var goods_num = parseInt($(this).parent().find("input[name='goods_num[]']").val());
                    var goods_final_amount = parseFloat($(this).parent().find("input[name='goods_final_amount[]']").val()).toFixed(2);
                    if(pre_discount > 1){
                        pre_amount = parseFloat(parseFloat(pre_amount)+parseFloat(parseInt(goods_num)*parseFloat(goods_final_amount)*parseFloat(pre_discount)/10)).toFixed(2);            //之前的价格
                    }else{
                        pre_amount = parseFloat(parseFloat(pre_amount)+parseFloat(parseInt(goods_num)*parseFloat(goods_final_amount))).toFixed(2);            //之前的价格
                    }

                    cur_amount = parseFloat(parseFloat(cur_amount)+parseFloat(parseInt(goods_num)*parseFloat(goods_final_amount)*parseFloat(discount)/10)).toFixed(2);
                    $(this).parent().find(".s_goods_discount").text(discount);
                    $(this).parent().find("input[name='goods_discount[]']").val(discount);
                    $(this).parent().find(".s_goods_discount").text(discount);
                }
            })


            total_amount = parseFloat(parseFloat(total_amount)-parseFloat(pre_amount)+parseFloat(cur_amount)).toFixed(2);
            final_amount = parseFloat(parseFloat(final_amount)-parseFloat(pre_amount)+parseFloat(cur_amount)).toFixed(2);
            zhaoling = parseFloat(parseFloat(cash)-parseFloat(final_amount)).toFixed(2);
            $('#total_amount').text(total_amount);
            $('#final_amount').text(final_amount);
            $('#zhaoling').text(zhaoling);

            $('.calculator').css('display', 'none');
            $('.calculator-content').css('display', 'none');

            $('.xuanze').removeClass('zhong');
        }

        /**
         * 添加数量
         */
        function add_num(num){
            var total_amount = parseFloat($('#total_amount').text()).toFixed(2);
            var final_amount = parseFloat($('#final_amount').text()).toFixed(2);
            var cash = parseFloat($('#cash').val()).toFixed(2);
            var all_amount = parseFloat(0).toFixed(2);

            $('.xuanze').each(function () {
                if($(this).hasClass('zhong')){         //选中的商品
                    var goods_final_amount = parseFloat($(this).parent().find("input[name='goods_final_amount[]']").val()).toFixed(2);
                    var goods_num = parseInt($(this).parent().find("input[name='goods_num[]']").val());
                    var goods_discount = parseInt($(this).parent().find("input[name='goods_discount[]']").val()).toFixed(2);

                    goods_num = parseInt(parseInt(goods_num)+parseInt(num));

                    if(goods_discount > 1){
                        all_amount = parseFloat(parseFloat(all_amount)+parseFloat(parseFloat(goods_final_amount)*parseInt(num)*parseFloat(goods_discount)/10)).toFixed(2);
                    }else{
                        all_amount = parseFloat(parseFloat(all_amount)+parseFloat(parseFloat(goods_final_amount)*parseInt(num))).toFixed(2);
                    }

                    $(this).parent().find("input[name='goods_num[]']").val(goods_num);
                    $(this).parent().find(".s_goods_num").text(goods_num);
                }
            })

            total_amount = parseFloat(parseFloat(total_amount)+parseFloat(all_amount)).toFixed(2);
            final_amount = parseFloat(parseFloat(final_amount)+parseFloat(all_amount)).toFixed(2);
            var zhaoling = parseFloat(parseFloat(cash)-parseFloat(final_amount)).toFixed(2);
            $('#total_amount').text(total_amount);
            $('#final_amount').text(final_amount);
            $('#zhaoling').text(zhaoling);

            //重置付款方式
            $('.pay').removeClass('pay-zhong');
            $('.pay-popup').css('visibility','hidden');
        }
        /**
         * 减少数量
         */
        function dec_num(num){
            var total_amount = parseFloat($('#total_amount').text()).toFixed(2);
            var final_amount = parseFloat($('#final_amount').text()).toFixed(2);
            var cash = parseFloat($('#cash').val()).toFixed(2);
            var all_amount = parseFloat(0).toFixed(2);

            $('.xuanze').each(function () {
                if($(this).hasClass('zhong')){         //选中的商品
                    var goods_final_amount = parseFloat($(this).parent().find("input[name='goods_final_amount[]']").val()).toFixed(2);
                    var goods_num = parseInt($(this).parent().find("input[name='goods_num[]']").val());
                    var goods_discount = parseInt($(this).parent().find("input[name='goods_discount[]']").val()).toFixed(2);

                    if(goods_num < num){
                        num = parseInt(goods_num);
                    }

                    goods_num = parseInt(parseInt(goods_num)-parseInt(num));


                    if(goods_discount > 1){
                        all_amount = parseFloat(parseFloat(all_amount)+parseFloat(parseFloat(goods_final_amount)*parseInt(num)*parseFloat(goods_discount)/10)).toFixed(2);
                    }else{
                        all_amount = parseFloat(parseFloat(all_amount)+parseFloat(parseFloat(goods_final_amount)*parseInt(num))).toFixed(2);
                    }

                    $(this).parent().find("input[name='goods_num[]']").val(goods_num);
                    $(this).parent().find(".s_goods_num").text(goods_num);

                    if(goods_num == 0){
                        $(this).parent().remove();
                    }
                }
            })

            total_amount = parseFloat(parseFloat(total_amount)-parseFloat(all_amount)).toFixed(2);
            final_amount = parseFloat(parseFloat(final_amount)-parseFloat(all_amount)).toFixed(2);
            var zhaoling = parseFloat(parseFloat(cash)-parseFloat(total_amount)).toFixed(2);
            $('#total_amount').text(total_amount);
//            $('#final_amount').text(final_amount);
            $('#final_amount').text(total_amount);
            $('#zhaoling').text(zhaoling);

            $('input[name=use_coupon_id]').val('');         //重置优惠券id
            $('#use_coupon_amount').text('');               //重置优惠券价格

            //重置付款方式
            $('.pay').removeClass('pay-zhong');
            $('.pay-popup').css('visibility','hidden');

//            layer.msg('优惠券已重置，请重新选择', {
//                icon: 3,
//                time: 1500
//            });
//            return false; //重要

        }
        /**
         * 设置数量
         */
        function set_num(num){
            var total_amount = parseFloat($('#total_amount').text()).toFixed(2);
            var final_amount = parseFloat($('#final_amount').text()).toFixed(2);
            var cash = parseFloat($('#cash').val()).toFixed(2);
            var all_amount = parseFloat(0).toFixed(2);
            var pre_amount = parseFloat(0).toFixed(2);      //之前的金额

            $('.xuanze').each(function(){
                if($(this).hasClass('zhong')){         //选中的商品
                    var goods_final_amount = parseFloat($(this).parent().find("input[name='goods_final_amount[]']").val()).toFixed(2);
                    var goods_num = parseInt($(this).parent().find("input[name='goods_num[]']").val());
                    var goods_discount = parseInt($(this).parent().find("input[name='goods_discount[]']").val()).toFixed(2);

//                    goods_num = parseInt(parseInt(goods_num)-parseInt(num));

                    if(goods_discount > 1){
                        pre_amount = parseFloat(parseFloat(pre_amount)+parseFloat(parseFloat(goods_final_amount)*parseInt(goods_num)*parseFloat(goods_discount)/10)).toFixed(2);
                        all_amount = parseFloat(parseFloat(all_amount)+parseFloat(parseFloat(goods_final_amount)*parseInt(num)*parseFloat(goods_discount)/10)).toFixed(2);
                    }else{
                        pre_amount = parseFloat(parseFloat(pre_amount)+parseFloat(parseFloat(goods_final_amount)*parseInt(goods_num))).toFixed(2);
                        all_amount = parseFloat(parseFloat(all_amount)+parseFloat(parseFloat(goods_final_amount)*parseInt(num))).toFixed(2);
                    }
                    console.log(goods_final_amount);
                    $(this).parent().find("input[name='goods_num[]']").val(num);
                    $(this).parent().find(".s_goods_num").text(num);
                }
            })


//            console.log(pre_amount);
//            console.log(all_amount);
            total_amount = parseFloat(parseFloat(total_amount)-parseFloat(pre_amount)+parseFloat(all_amount)).toFixed(2);
            final_amount = parseFloat(parseFloat(final_amount)-parseFloat(pre_amount)+parseFloat(all_amount)).toFixed(2);
            var zhaoling = parseFloat(parseFloat(cash)-parseFloat(total_amount)).toFixed(2);
            $('#total_amount').text(total_amount);
            $('#final_amount').text(total_amount);
            $('#zhaoling').text(zhaoling);

            $('input[name=use_coupon_id]').val('');         //重置优惠券id
            $('#use_coupon_amount').text('');               //重置优惠券价格


            //重置付款方式
            $('.pay').removeClass('pay-zhong');
            $('.pay-popup').css('visibility','hidden');

//            layer.msg('优惠券已重置，请重新选择', {
//                icon: 3,
//                time: 1500
//            });
//            return false; //重要
        }

        /**
         * 使用优惠券
         */
        function use_coupon(amount,coupon_id){
            var total_amont = parseFloat($('#total_amount').text()).toFixed(2);
            var cash = parseFloat($('#cash').val()).toFixed(2);
            $('input[name=use_coupon_id]').val(coupon_id);
            var final_amount = parseFloat(parseFloat(total_amont)-parseFloat(amount)).toFixed(2);      //最终支付价
            var zhaoling = parseFloat(parseFloat(cash)-parseFloat(final_amount)).toFixed(2);
            $('#final_amount').text(final_amount);
            $('#zhaoling').text(zhaoling);
            $('#use_coupon_amount').text(amount);           //放置优惠券价格

            //重置付款方式
            $('.pay').removeClass('pay-zhong');
            $('.pay-popup').css('visibility','hidden');

            $('.coupon').css('display', 'none');
            $('.coupon-content').css('display', 'none');
        }
        /**
         * 结账
         */
        function jiezhang(){
            var mobile = $('input[name=mobile]').val();
            var yue = $('input[name=yue]').val();
            var coupon_id = $('input[name=use_coupon_id]').val();
            var qrcode = $('input[name=qrcode]').val();   //支付码
            var goods_id = [];                  //商品id
            var goods_spec_id = [];             //商品属性id
            var goods_num = [];                 //商品数量
            var goods_discount = [];            //商品折扣
            var pay_type = 0                    //支付方式
            var uid = $('#user_id').text();     //会员id
            var cash = parseFloat($('#cash').val()).toFixed(2);
            var is_yuding = 0;

            $('.xuanze').each(function () {
                goods_id.push($(this).parent().find("input[name='goods_id[]']").val());
                goods_spec_id.push($(this).parent().find("input[name='goods_spec_id[]']").val());
                goods_num.push($(this).parent().find("input[name='goods_num[]']").val());
                goods_discount.push($(this).parent().find("input[name='goods_discount[]']").val());
            })

            if(goods_id.length<1){
                layer.msg('请选择商品', {
                    icon: 2,
                    time: 1500
                });
                return false; //重要
            }

            $('.pay').each(function () {
                if($(this).hasClass('pay-zhong')){
                    pay_type = $(this).attr('data-id');
                    return false
                }
            })

            $.post("{:url('Pay/index')}",
                {mobile:mobile,yue:yue,coupon_id:coupon_id,qrcode:qrcode,goods_id,goods_spec_id,goods_num:goods_num,goods_discount:goods_discount,pay_type:pay_type,uid:uid,cash:cash,is_yuding:is_yuding},
                function(data){
                    if(data.code == 1){         //支付成功
                        $('#print').html(data.data);
                        layer.msg('付款成功', {
                            icon: 1,
                            time: 1000
                        }, function (data) {
                            print();
                            location.reload();
                        });
                    }else{
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 1500
                        });
                        return false; //重要
                    }
                }
            );
        }

        function yuding(){
            var mobile = $('input[name=mobile]').val();
            var yue = $('input[name=yue]').val();
            var coupon_id = $('input[name=use_coupon_id]').val();
            var qrcode = $('input[name=qrcode]').val();   //支付码
            var goods_id = [];                  //商品id
            var goods_spec_id = [];             //商品属性id
            var goods_num = [];                 //商品数量
            var goods_discount = [];            //商品折扣
            var pay_type = 0                    //支付方式
            var uid = $('#user_id').text();     //会员id
            var cash = parseFloat($('#cash').val()).toFixed(2);
            var is_yuding = 1;

            $('.xuanze').each(function () {
                goods_id.push($(this).parent().find("input[name='goods_id[]']").val());
                goods_spec_id.push($(this).parent().find("input[name='goods_spec_id[]']").val());
                goods_num.push($(this).parent().find("input[name='goods_num[]']").val());
                goods_discount.push($(this).parent().find("input[name='goods_discount[]']").val());
            })

            if(goods_id.length<1){
                layer.msg('请选择商品', {
                    icon: 2,
                    time: 1500
                });
                return false; //重要
            }

            $('.pay').each(function () {
                if($(this).hasClass('pay-zhong')){
                    pay_type = $(this).attr('data-id');
                    return false
                }
            })

            $.post("{:url('Pay/index')}",
                {mobile:mobile,yue:yue,coupon_id:coupon_id,qrcode:qrcode,goods_id,goods_spec_id,goods_num:goods_num,goods_discount:goods_discount,pay_type:pay_type,uid:uid,cash:cash,is_yuding:is_yuding},
                function(data){
                    if(data.code == 1){         //支付成功
                        $('#print').html(data.data);
                        layer.msg('付款成功', {
                            icon: 1,
                            time: 1000
                        }, function (data) {
                            print();
                            location.reload();
                        });
                    }else{
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 1500
                        });
                        return false; //重要
                    }
                }
            );
        }

        /**
         * 挂单
         */
        function guadan(){
            var mobile = $('input[name=mobile]').val();
            var yue = $('input[name=yue]').val();
            var coupon_id = $('input[name=use_coupon_id]').val();
            var qrcode = $('input[name=qrcode]').val();   //支付码
            var goods_id = [];                  //商品id
            var goods_spec_id = [];             //商品属性id
            var goods_num = [];                 //商品数量
            var goods_discount = [];            //商品折扣
            var pay_type = 0                    //支付方式
            var uid = $('#user_id').text();     //会员id
            var cash = parseFloat($('#cash').val()).toFixed(2);

            $('.xuanze').each(function () {
                goods_id.push($(this).parent().find("input[name='goods_id[]']").val());
                goods_spec_id.push($(this).parent().find("input[name='goods_spec_id[]']").val());
                goods_num.push($(this).parent().find("input[name='goods_num[]']").val());
                goods_discount.push($(this).parent().find("input[name='goods_discount[]']").val());
            })

            if(goods_id.length<1){
                layer.msg(data.msg, {
                    icon: 2,
                    time: 1500
                });
                return false; //重要
            }

            $('.pay').each(function () {
                if($(this).hasClass('pay-zhong')){
                    pay_type = $(this).attr('data-id');
                    return false
                }
            })

            $.post("{:url('Guadan/index')}",
                {mobile:mobile,yue:yue,coupon_id:coupon_id,qrcode:qrcode,goods_id,goods_spec_id,goods_num:goods_num,goods_discount:goods_discount,pay_type:pay_type,uid:uid,cash:cash},
                function(data){
                    if(data.code == 1){         //支付成功
                        layer.msg('挂单成功', {
                            icon: 1,
                            time: 1500
                        },function(){
                            location.reload();
                        });
                        return false; //重要
                    }else{
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 1500
                        });
                        return false; //重要
                    }
                }
            );
        }

        /**
         * 打印小票
         */
        function print(){
            if (!!window.ActiveXObject || "ActiveXObject" in window) {
                remove_ie_header_and_footer();
            }
            var newWindow = window.open("打印窗口", "_blank");
            var docStr = $("#print-area").html();
            newWindow.document.write(docStr);
            newWindow.document.close();
            newWindow.print();
            newWindow.close();
        }
        /**
         * 取出打印的页眉页脚
         */
        function remove_ie_header_and_footer(){
            var hkey_root, hkey_path, hkey_key;
            hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
            try {
                var RegWsh = new ActiveXObject("WScript.Shell");
                RegWsh.RegWrite(hkey_path + "header", "");
                RegWsh.RegWrite(hkey_path + "footer", "");
            } catch (e) {}
        }

        /**
         * 获取会员信息
         */
        function get_member(){
            var user_mobile = $('input[name=user_mobile]').val();
            console.log(user_mobile);
            if(user_mobile == ''){
                layer.msg('请输入会员手机号或会员卡号', {
                    icon: 2,
                    time: 1500
                });
                return false; //重要
            }

            $.post("{:url('Index/get_member')}",
                {mobile:user_mobile},
                function(data){
                    if(data.code == 1){
                        $('#member_money').text(data.data.user_money);
                        $('#yue').val(data.data.user_money);
                        //放入会员信息
                        $('#vip_logo').attr('src',data.data.logo);
                        $('#vip_realname').text(data.data.realname);
                        $('#vip_level').text(data.data.level_title);
                        $('#vip_coupon').text('拥有'+data.data.coupon_count+'张优惠券');
                        $('#vip_pay_code').text('会员卡：'+data.data.pay_code);
                        $('#vip_mobile').text('手机号：'+data.data.mobile);
                        $('#vip_money').text('余额：'+data.data.user_money);
                        $('#vip_points').text('积分：'+data.data.pay_points);

                        $('.member').css('display', 'block');
                        $('.member-content').css('display', 'block');


                        if(user_id != data.data.uid){       //会员重置
                            $('#list').empty();              //清空商品
                            $('#coupon').empty();
                            $('#total_amount').text('0.00');
                            $('#final_amount').text('0.00');
                            $('#zhaoling').text('0.00');
                            $('input[name=use_coupon_id]').val('');
                            $('#use_coupon_amount').text(0);
                        }else{
//                                $('input[name=use_coupon_id]').val('');
//                                $('#use_coupon_amount').text(0);
                            var zhaoling = parseFloat(parseFloat(cash)-parseFloat(total_amount)).toFixed(2);
                            $('#zhaoling').text(zhaoling);
//                                $('#final_amount').text(total_amount);
                        }
                        $('#user_id').text(data.data.uid);
                    }else{
                        layer.msg('找不会员信息，请重新查询', {
                            icon: 2,
                            time: 1000
                        });
                        $('#list').empty();              //清空商品
                        $('#coupon').empty();
                        $('#total_amount').text('0.00');
                        $('#final_amount').text('0.00');
                        $('#zhaoling').text('0.00');
                        $('input[name=use_coupon_id]').val('');
                        $('#use_coupon_amount').text(0);
                        $('#user_id').text('');

                        return false;
                    }
                }
            );

        }

        /**
         * 会员充值
         */
        function recharge(){
            var user_mobile = $('input[name=user_mobile]').val();           //会员手机信息
            var recharge_money = $('input[name=recharge_money]').val();           //充值金额
            var recharge_code = $('input[name=recharge_code]').val();           //付款码
            var pay_type = '';              //支付方式
            $('.again').each(function () {
                if($(this).hasClass('again-zhong')){
                    pay_type = $(this).attr('data-id');
                    return false
                }
            })

            $.post("{:url('Recharge/index')}",
                {user_mobile:user_mobile,pay_type:pay_type,price:recharge_money,pay_code:recharge_code},
                function(data){
                    if(data.code == 1){
                        layer.msg('充值成功', {
                            icon: 1,
                            time: 1500
                        },function (data) {
                            location.reload();
                        });

                        return false; //重要
                    }else{
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 1500
                        });
                        return false; //重要
                    }
                }
            );
        }
        /**
         * 找零
         */
        function count_zhaoling(){
            var cash = parseFloat($('#cash').val()).toFixed(2);
            var final_amount = parseFloat($('#final_amount').text()).toFixed(2);
            var zhaoling = parseFloat(parseFloat(cash)-parseFloat(final_amount)).toFixed(2);
            $('#zhaoling').text(zhaoling);
        }


        /**
         * @Author      Lingyun
         * @Description 项目交班
         * @DateTime    2018-06-12
         * @Description
         * @return      {[type]}   [description]
         */
        function jiaoban(){
            $.post("{:url('Jiaoban/index')}",
                {id:1},
                function(data){
                    if(data.code == 1){
                        $('#print').html(data.data);
                        print();
                        location.reload();
                    }else{
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 1500
                        });
                        return false; //重要
                    }
                }
            );
        }
        /**
         * 日结
         */
        function rijie(){
            $.post("{:url('Jiaoban/rejie')}",
                {id:1},
                function(data){
                    if(data.code == 1){
                        $('#print').html(data.data);
                        print();
                        location.reload();
                    }else{
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 1500
                        });
                        return false; //重要
                    }
                }
            );
        }

        /**
         * 清空收银台
         */
        function qingkong(){
            location.reload();
        }

        /**
         * 退出登录
         */
        function logout() {
            layer.confirm('确定退出登录吗？', {
                btn: ['确定', '取消']
            }, function () {
                $.post("{:url('Index/out')}", {
                        id: 1
                    },
                    function (data) {
                        if (data.code == 1) {
                            layer.msg('退出登录成功', {
                                icon: 1,
                                time: 1000
                            }, function (data) {
                                window.location.href = "{:url('Login/index')}";
                            });
                        } else {
                            layer.msg('网络请求失败，请稍后再试', {
                                icon: 2
                            });
                        }
                    }
                );
            }, function () {});
        }

    </script>


</body>

</html>